<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Internationalization_LanguageForm extends Zend_View_Helper_Abstract
{
    /**
     *  this helper renders a language selector
     *  it also processes the selected language
     *  it must be rendered above the content in order for the current
     *  content to reflect the language selection
     */
    public function languageForm()
    {
        //process form if this is a post back
        if (Core_Filter_Post::has('setLang')) {
            Core_Language::setLanguage($_POST['language']);
            // @todo: this needs to redirect so it loads the whole page in the new language
        }

        $currentLanguage = Core_Language::getLanguage();

        $languageSelector = $this->view->selectLanguage('language', $currentLanguage);
        $xhtml  = '<form action="' . $this->view->moduleAction() . '" method="post">';
        $xhtml .= '<p>' . $languageSelector . '</p>';
        $xhtml .= '<p>' . $this->view->formSubmit('setLang', $this->view->getTranslation('Set Language')) . '</p>';
        $xhtml .= '</form>';
        return $xhtml;
    }
}